package cn.sany.cterminal.config.mysql;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 *
 * @Project : forklift
 * @Package : cn.sany.forklift.config
 * @Class : MybatisConfig
 * @Description : MybatisConfig
 * @author : zhouxing
 * @CreateDate : 2020-07-13 17:16:56
 * @version : V0.5
 * @Copyright : 2020 sany.com Inc. All rights reserved.
 * @Reviewed :
 * @UpateLog :    Name    Date    Reason/Contents
 *             ---------------------------------------
 *                ****    ****    ****
 *
 */
@Configuration
public class MybatisConfig {
    @Autowired
    private DataSourceProperties dataSourceProperties;
    private final Environment env;
    @Autowired
    MybatisConfig(final Environment env) {
        this.env = env;
    }
    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(dataSourceProperties.getUrl());
        dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
        dataSource.setUsername(dataSourceProperties.getUsername());
        dataSource.setPassword(dataSourceProperties.getPassword());
        return dataSource;

    }
}
